﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using System.IO;
using ZX.EHR.ResumeParseLib;
using ZX.DBModule;
using System.Text;

namespace ZX.WebApp.EHR
{
    public partial class hrAjax :BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string flag = this.GetStringFromQueryString("flag", "");
            if (flag.Trim() == "getresume") //获取简历
            {
                string id = this.GetStringFromQueryString("id", string.Empty);
                if (id == string.Empty)
                {
                    HttpContext.Current.Response.Write("-1");
                    return;
                }
                try
                {
                    ZX.EHR.Library.hrCandidate instance = ZX.Common.Globals.getEntity("hrCandidate") as ZX.EHR.Library.hrCandidate;
                    ZX.BLL.Extend.BaseBussnies hrBll = new ZX.BLL.Extend.BaseBussnies(instance);
                    string condition = string.Format("ID='{0}'", id);
                    ZX.EHR.Library.hrCandidate hrcandidate = hrBll.GetEntityByCondition(condition) as ZX.EHR.Library.hrCandidate;
                    if (hrcandidate.ResumeHTML.Trim() == string.Empty)
                    {
                        HttpContext.Current.Response.Write("-1");
                        return;
                    }
                    //IdentifyEncoding getEncoding = new IdentifyEncoding();
                    string htmlContent = Server.HtmlDecode(hrcandidate.ResumeHTML);
                    string tempEncodingStr = "gb2312";
                    try
                    {
                        string[] token = htmlContent.Split("\r\n".ToCharArray());
                        tempEncodingStr = token[0].Substring(token[0].IndexOf("<") + 1, token[0].IndexOf(">") - token[0].IndexOf("<") - 1);
                    }
                    catch
                    { }
                    File.WriteAllText(Request.PhysicalApplicationPath + "EHR/tempfiles/" + hrcandidate.Name + ".htm", htmlContent, System.Text.Encoding.GetEncoding(tempEncodingStr));
                    HttpContext.Current.Response.Write(hrcandidate.Name + ".htm");
                    return;
                }
                catch
                {
                }
                HttpContext.Current.Response.Write("-1");
            }
            if (flag.Trim() == "deleteemployee") //删除员工附属信息,当删除员工信息时，联动删除员工附属信息
            {
                //包括工作经历，教育经历，技能信息，工作合同，培训经历，项目经历，薪酬信息，岗位异动信息，离职信息
                 string id = this.GetStringFromQueryString("id", string.Empty);
                if (id == string.Empty)
                {
                    HttpContext.Current.Response.Write("-1");
                    return;
                }
                BaseEntity instance = null;
                ZX.BLL.Extend.BaseBussnies baseBll = null;
                try
                {
                    string[] tableName = { "hrEmployeeExperiences", "hrEmployeeEducations", "hrEmployeeSkills", "hrEmployeeContracts", "hrEmployeeTrainings", "hrEmployeeProjects", "hrEmployeeSalary", "hrEmployeePositions", "hrEmployeeAffairs" };
                    foreach (string s in tableName)
                    {
                        instance = ZX.Common.Globals.getEntity(s) as BaseEntity;
                        string condition = string.Format("EmployeeID='{0}'", id);
                        baseBll = new ZX.BLL.Extend.BaseBussnies(instance);
                        baseBll.delete(condition);
                    }
                    HttpContext.Current.Response.Write("0");
                    return;
                }
                catch
                { }
                HttpContext.Current.Response.Write("-1");
            }
            //if (flag.Trim() == "modifyinterviewstatus") //修改面试者状态信息
            //{
            //    string id = this.GetStringFromQueryString("id", string.Empty);
            //    if (id == string.Empty)
            //    {
            //        HttpContext.Current.Response.Write("-1");
            //        return;
            //    }
            //    string statusStr = this.GetStringFromQueryString("status", string.Empty);
            //    byte status = 0;
            //    try 
            //    {
            //        status = byte.Parse(statusStr);
            //    }
            //    catch {
            //        HttpContext.Current.Response.Write("-1");
            //        return;
            //    }
            //    if (status == 0)
            //    {
            //        HttpContext.Current.Response.Write("-1");
            //        return;
            //    }
            //    try
            //    {
            //        string errMsg = string.Empty;
            //        string[] listId = id.Split('_');
            //        ZX.EHR.Library.hrCandidate instance = ZX.Common.Globals.getEntity("hrCandidate") as ZX.EHR.Library.hrCandidate;
            //        ZX.BLL.Extend.BaseBussnies hrBll = new ZX.BLL.Extend.BaseBussnies(instance);
            //        foreach (string s in listId)
            //        {
            //            if (s.Trim() == string.Empty) continue;
            //            string condition = string.Format("ID='{0}'", s);
            //            try
            //            {
            //                ZX.EHR.Library.hrCandidate hrcandidate = hrBll.GetEntityByCondition(condition) as ZX.EHR.Library.hrCandidate;
            //                hrBll.Update(hrcandidate);
            //            }
            //            catch
            //            {
            //                errMsg = errMsg + s+"_";
            //            }
            //        }
            //        if (errMsg == string.Empty)
            //        {
            //            HttpContext.Current.Response.Write("0");
            //        }
            //        else
            //        {
            //            HttpContext.Current.Response.Write("0"+errMsg);
            //        }
            //        return;
            //    }
            //    catch { }
            //    HttpContext.Current.Response.Write("-1");
            //}
            //if (flag.Trim() == "interviewinfo")//获取应聘者面试信息
            //{
            //    string id = this.GetStringFromQueryString("id", string.Empty);
            //    if (id == string.Empty)
            //    {
            //        HttpContext.Current.Response.Write("0");//获取信息失败
            //        return;
            //    }
            //    try
            //    {
            //        ZX.EHR.Library.hrInterview instance = ZX.Common.Globals.getEntity("hrInterview") as ZX.EHR.Library.hrInterview;
            //        ZX.BLL.Extend.BaseBussnies hrBll = new ZX.BLL.Extend.BaseBussnies(instance);
            //        string condition = string.Format("CandidateID='{0}'", id);
            //        IList<BaseEntity> list = hrBll.GetEntitysByCondition(condition);
            //        ZX.EHR.Library.DatUser user = ZX.Common.Globals.getEntity("DatUser") as ZX.EHR.Library.DatUser;
            //        ZX.BLL.Extend.BaseBussnies userBll = new ZX.BLL.Extend.BaseBussnies(user);
            //        StringBuilder sb = new StringBuilder();
            //        foreach (BaseEntity entity in list)
            //        {
            //            ZX.EHR.Library.hrInterview hrinterview = entity as ZX.EHR.Library.hrInterview;
            //            //获取面试官姓名
            //            condition = string.Format("EmpID='{0}'", hrinterview.InterviewerID);
            //            ZX.EHR.Library.DatUser user2 = userBll.GetEntityByCondition(condition) as ZX.EHR.Library.DatUser;
            //            sb.Append(user2.UName+"_");//面试官姓名
            //            sb.Append(hrinterview.InterviewDate.ToString("yyyy-MM-dd")+"_");//面试时间
            //            sb.Append(hrinterview.IsPassed.ToString() + "_");//面试结果
            //            sb.Append(hrinterview.Appraise);//面试点评
            //            sb.Append("\r\n");
            //        }
            //        if (sb.ToString() != string.Empty)
            //        {
            //            HttpContext.Current.Response.Write(sb.ToString());
            //            return;
            //        }
            //    }
            //    catch { }
            //    HttpContext.Current.Response.Write("0");//获取信息失败
            //}
            //if (flag.Trim() == "ruzhishenhetijiao") //入职审核单提交
            //{
            //    string id = this.GetStringFromQueryString("id", string.Empty);
            //    if (id == string.Empty)
            //    {
            //        HttpContext.Current.Response.Write("-1");
            //        return;
            //    }
            //    try
            //    {
            //        string errMsg = string.Empty;
            //        string[] listId = id.Split('_');
            //        ZX.EHR.Library.hrPreEnterAudit instance = ZX.Common.Globals.getEntity("hrPreEnterAudit") as ZX.EHR.Library.hrPreEnterAudit;
            //        instance.Title = DateTime.Now.ToString("yyyy年MM月dd日") + " 待审核入职人员";
            //        instance.ReportID = this.User.EmpID; //提报人
            //        instance.ReportDate = DateTime.Now; //提报时间
            //        Guid guid = Guid.NewGuid();
            //        instance.ID = guid;
            //        int num = 0;
            //        foreach (string s in listId)
            //        {
            //            if (s.Trim() == string.Empty) continue;
            //            num++;
            //        }
            //        instance.PassRate = "0/" + num; //审核通过率
            //        ZX.BLL.Extend.BaseBussnies hrBll = new ZX.BLL.Extend.BaseBussnies(instance);
            //        hrBll.Insert();  //将数据插入hrPreEnterAudit表中
            //        //将提交表单人员添加到hrPreEnterAuditDetail中
            //        ZX.EHR.Library.hrPreEnterAuditDetail instance2 = null;
            //        foreach (string s in listId)
            //        {
            //            if (s.Trim() == string.Empty) continue;
            //            try
            //            {
            //                instance2 = ZX.Common.Globals.getEntity("hrPreEnterAuditDetail") as ZX.EHR.Library.hrPreEnterAuditDetail;
            //                instance2.AuditID = guid;  //审核单ID
            //                instance2.DetailID = Guid.NewGuid(); //ID号
            //                instance2.CandidateID = new Guid(s); //候选人ID
            //                instance2.AuditStatus = 0; //审核状态为未审核
            //                ZX.BLL.Extend.BaseBussnies hrBll2 = new ZX.BLL.Extend.BaseBussnies(instance2);
            //                hrBll2.Insert();  //将数据插入hrPreEnterAuditDetail明细表中
            //                //接下来更新候选人表中的状态信息
            //                string condition = string.Format("ID='{0}'", s);
            //                ZX.EHR.Library.hrCandidate instance3 = ZX.Common.Globals.getEntity("hrCandidate") as ZX.EHR.Library.hrCandidate;
            //                ZX.BLL.Extend.BaseBussnies hrBll3 = new ZX.BLL.Extend.BaseBussnies(instance3);
            //                ZX.EHR.Library.hrCandidate hrcandidate = hrBll3.GetEntityByCondition(condition) as ZX.EHR.Library.hrCandidate;
            //                hrBll.Update(hrcandidate);
            //            }
            //            catch
            //            {
            //                errMsg = errMsg + s + "_";
            //            }
            //        }
            //        if (errMsg == string.Empty)
            //        {
            //            HttpContext.Current.Response.Write("0");
            //        }
            //        else
            //        {
            //            HttpContext.Current.Response.Write("0" + errMsg);
            //        }
            //        return;
            //    }
            //    catch { }
            //    HttpContext.Current.Response.Write("-1");
            //}
            //if (flag.Trim() == "ruzhishenheluyong") //入职审核录用
            //{
            //    string id = this.GetStringFromQueryString("id", string.Empty);
            //    if (id == string.Empty)
            //    {
            //        HttpContext.Current.Response.Write("-1");
            //        return;
            //    }
            //    string AuditId = this.GetStringFromQueryString("auditid", string.Empty);
            //    if (AuditId == string.Empty)
            //    {
            //        HttpContext.Current.Response.Write("-1");
            //        return;
            //    }
            //    string result = this.GetStringFromQueryString("result", string.Empty); //审核结果
            //    if (result == string.Empty)
            //    {
            //        HttpContext.Current.Response.Write("-1");
            //        return;
            //    }
            //    try
            //    {
            //        byte testByte = byte.Parse(result);
            //    }
            //    catch {
            //        HttpContext.Current.Response.Write("-1");
            //        return;
            //    }
            //    try
            //    {
            //        string errMsg = string.Empty;
            //        string[] listId = id.Split('_');
            //        ZX.EHR.Library.hrPreEnterAuditDetail instance = ZX.Common.Globals.getEntity("hrPreEnterAuditDetail") as ZX.EHR.Library.hrPreEnterAuditDetail;
            //        ZX.BLL.Extend.BaseBussnies hrBll = new ZX.BLL.Extend.BaseBussnies(instance);
            //        int num = 0; //审核通过人数
            //        //更新hrPreEnterAuditDetail表中候选人入职审核状态
            //        foreach (string s in listId)
            //        {
            //            if (s.Trim() == string.Empty) continue;
            //            string condition = string.Format("DetailID='{0}'", s);
            //            try
            //            {
            //                ZX.EHR.Library.hrPreEnterAuditDetail hrpreauditdetail = hrBll.GetEntityByCondition(condition) as ZX.EHR.Library.hrPreEnterAuditDetail;
            //                //更新候选人状态
            //                ZX.EHR.Library.hrCandidate hrCandidateInstance = ZX.Common.Globals.getEntity("hrCandidate") as ZX.EHR.Library.hrCandidate;
            //                ZX.BLL.Extend.BaseBussnies hrCandidateBll = new ZX.BLL.Extend.BaseBussnies(hrCandidateInstance);
            //                string hrCandidateCondition = string.Format("ID='{0}'", hrpreauditdetail.CandidateID.ToString());
            //                ZX.EHR.Library.hrCandidate hrCandidateEntry = hrCandidateBll.GetEntityByCondition(hrCandidateCondition) as ZX.EHR.Library.hrCandidate;//候选人
            //                //根据候选人ID获取招聘需求信息
            //                ZX.EHR.Library.hrRequirement hrRequirementInstance = ZX.Common.Globals.getEntity("hrRequirement") as ZX.EHR.Library.hrRequirement;
            //                ZX.BLL.Extend.BaseBussnies hrRequirementBll = new ZX.BLL.Extend.BaseBussnies(hrRequirementInstance);
            //                string hrRequirementCondition = string.Format("ID='{0}'", hrCandidateEntry.RequirementID.ToString());
            //                ZX.EHR.Library.hrRequirement hrRequirementEntry = hrRequirementBll.GetEntityByCondition(hrRequirementCondition) as ZX.EHR.Library.hrRequirement;//招聘需求
            //                if (byte.Parse(result) == 7) //录用
            //                {
            //                    //判断招聘需求数据表中已招聘人数是否达到允许可招聘的人数,已达到则不允许再增加
            //                    if (hrRequirementEntry.EmployeedNum >= hrRequirementEntry.AvailableNumber)
            //                    {
            //                        errMsg = errMsg + "岗位:" + hrRequirementEntry.PositionName + " 已招满,候选人:" + hrCandidateEntry.CandidateName + " 审核无法通过\r\n";
            //                        continue;
            //                    }
            //                    //同时更新招聘需要中的已招人数
            //                    hrRequirementEntry.EmployeedNum++;
            //                    if (hrRequirementEntry.EmployeedNum == hrRequirementEntry.AvailableNumber)
            //                    {
            //                        hrRequirementEntry.Status = 4;//招聘完成
            //                    }
            //                    hrRequirementBll.Update(hrRequirementEntry);                               
            //                    hrpreauditdetail.AuditStatus = 1;//修改候选人预入职状态为审核通过 
            //                    hrCandidateEntry.InterviewStatus = 7;//将候选人状态改为审核通过                         
            //                    num++;
            //                }
            //                else //不录用
            //                {
            //                    hrpreauditdetail.AuditStatus = 2;//修改候选人预入职状态为审核不通过
            //                    hrCandidateEntry.InterviewStatus = 8;//将候选人状态改为审核不通过    
            //                }
            //                //更新候选人预入职状态
            //                hrBll.Update(hrpreauditdetail);
            //                //更新候选人状态                     
            //                hrCandidateBll.Update(hrCandidateEntry);
            //            }
            //            catch(Exception ex)
            //            {
            //                errMsg = errMsg + ex.Message+"\r\n";
            //            }
            //        }
            //        //更新hrPreEnterAudit表中通过率
            //        ZX.EHR.Library.hrPreEnterAudit instance2 = ZX.Common.Globals.getEntity("hrPreEnterAudit") as ZX.EHR.Library.hrPreEnterAudit;
            //        ZX.BLL.Extend.BaseBussnies hrBll2 = new ZX.BLL.Extend.BaseBussnies(instance2);
            //        string condition2 = string.Format("ID='{0}'", AuditId);
            //        ZX.EHR.Library.hrPreEnterAudit hrpreenterAudit = hrBll2.GetEntityByCondition(condition2) as ZX.EHR.Library.hrPreEnterAudit;
            //        int tempNum = int.Parse(hrpreenterAudit.PassRate.Split('/')[0]);
            //        int tempTotalNum=int.Parse(hrpreenterAudit.PassRate.Split('/')[1]);
            //        if (tempNum + num >= tempTotalNum)
            //        {
            //            hrpreenterAudit.PassRate = tempTotalNum.ToString() + "/" + tempTotalNum.ToString();
            //        }
            //        else
            //        {
            //            hrpreenterAudit.PassRate = (tempNum + num).ToString() + "/" + tempTotalNum.ToString();
            //        }
            //        hrBll2.Update(hrpreenterAudit);
            //        //错误信息
            //        if (errMsg == string.Empty)
            //        {
            //            HttpContext.Current.Response.Write("0");
            //        }
            //        else
            //        {
            //            HttpContext.Current.Response.Write("0" + errMsg);
            //        }
            //        return;
            //    }
            //    catch { }
            //    HttpContext.Current.Response.Write("-1");
            //}
            if (flag.Trim() == "addresumetype") //将人才简历添加到简历类别
            {
                string id = this.GetStringFromQueryString("id", string.Empty);
                if (id == string.Empty)
                {
                    HttpContext.Current.Response.Write("-1");
                    return;
                }
                string resumetype = this.GetStringFromQueryString("resumetype", string.Empty);
                if (resumetype == string.Empty)
                {
                    HttpContext.Current.Response.Write("-1");
                    return;
                }
                try
                {
                    string errMsg = string.Empty;
                    string[] listId = id.Split('_');
                    ZX.EHR.Library.hrCandidate instance = ZX.Common.Globals.getEntity("hrCandidate") as ZX.EHR.Library.hrCandidate;
                    ZX.BLL.Extend.BaseBussnies hrBll = new ZX.BLL.Extend.BaseBussnies(instance);
                    foreach (string s in listId)
                    {
                        if (s.Trim() == string.Empty) continue;
                        string condition = string.Format("ID='{0}'", s);
                        try
                        {
                            ZX.EHR.Library.hrCandidate hrcandidate = hrBll.GetEntityByCondition(condition) as ZX.EHR.Library.hrCandidate;
                            hrBll.Update(hrcandidate);
                        }
                        catch
                        {
                            errMsg = errMsg + s + "_";
                        }
                    }
                    if (errMsg == string.Empty)
                    {
                        HttpContext.Current.Response.Write("0");
                    }
                    else
                    {
                        HttpContext.Current.Response.Write("0" + errMsg);
                    }
                    return;
                }
                catch { }
                HttpContext.Current.Response.Write("-1");
            }
            if (flag.Trim() == "getcandidateidbydetailid")  //根据DetailID获取简历候选人ID
            { 
                string id = this.GetStringFromQueryString("id", string.Empty);
                if (id == string.Empty)
                {
                    HttpContext.Current.Response.Write("-1");
                    return;
                }
                try
                {
                    ZX.EHR.Library.hrPreEnterAuditDetail instance = ZX.Common.Globals.getEntity("hrPreEnterAuditDetail") as ZX.EHR.Library.hrPreEnterAuditDetail;
                    ZX.BLL.Extend.BaseBussnies hrBll = new ZX.BLL.Extend.BaseBussnies(instance);
                    string condition = string.Format("DetailID='{0}'", id);
                    ZX.EHR.Library.hrPreEnterAuditDetail o = hrBll.GetEntityByCondition(condition) as ZX.EHR.Library.hrPreEnterAuditDetail;
                    HttpContext.Current.Response.Write(o.CandidateID.ToString());
                }
                catch
                { }
                HttpContext.Current.Response.Write("-1");
            }
            if (flag.Trim() == "yingpinruzhi") //应聘者入职
            {
                string deptId = this.GetStringFromQueryString("deptId", string.Empty);//获取部门ID
                string positionId = this.GetStringFromQueryString("positionId", string.Empty);//岗位ID
                string detailId = this.GetStringFromQueryString("detailId", string.Empty);//hrPreEnterAuditDetail表中的DetailID,用来获取候选人ID
                if (deptId == string.Empty || positionId == string.Empty || detailId == string.Empty)
                {
                    HttpContext.Current.Response.Write("-1");
                    return;
                }
                try
                {
                    //先根据detailId获取候选人ID，再根据候选人ID获取候选人基本信息，再将候选人信息添加到员工信息中
                    //获取候选人ID
                    ZX.EHR.Library.hrPreEnterAuditDetail hrAuditDetailInstance = ZX.Common.Globals.getEntity("hrPreEnterAuditDetail") as ZX.EHR.Library.hrPreEnterAuditDetail;
                    ZX.BLL.Extend.BaseBussnies hrAuditDetailBll = new ZX.BLL.Extend.BaseBussnies(hrAuditDetailInstance);
                    string condition = string.Format("DetailID='{0}'", detailId);
                    ZX.EHR.Library.hrPreEnterAuditDetail hrAuditDetailEntry = hrAuditDetailBll.GetEntityByCondition(condition) as ZX.EHR.Library.hrPreEnterAuditDetail;
                    Guid candateId = hrAuditDetailEntry.CandidateID;//候选人ID
                    //根据候选人ID获取候选人实例
                    ZX.EHR.Library.hrCandidate hrCandidateInstance = ZX.Common.Globals.getEntity("hrCandidate") as ZX.EHR.Library.hrCandidate;
                    ZX.BLL.Extend.BaseBussnies hrCandidateBll = new ZX.BLL.Extend.BaseBussnies(hrCandidateInstance);
                    string hrCandidateCondition = string.Format("ID='{0}'", candateId.ToString());
                    ZX.EHR.Library.hrCandidate hrCandidateEntry = hrCandidateBll.GetEntityByCondition(hrCandidateCondition) as ZX.EHR.Library.hrCandidate;//候选人
                    hrCandidateBll.Update(hrCandidateEntry);
                    //将候选人信息插入到hrEmployee表中
                    ZX.EHR.Library.hrEmployee hrEmployeeInstance = ZX.Common.Globals.getEntity("hrEmployee") as ZX.EHR.Library.hrEmployee;
                    hrEmployeeInstance.ID = Guid.NewGuid();
                    hrEmployeeInstance.IDCardNO = hrCandidateEntry.IDCardNo;//身份证号码
                    hrEmployeeInstance.CName = hrCandidateEntry.Name;//姓名
                    hrEmployeeInstance.Gender = hrCandidateEntry.Gender;//性别
                    hrEmployeeInstance.PhoneNo = hrCandidateEntry.PhoneNO;//手机
                    hrEmployeeInstance.Email = hrCandidateEntry.Email;
                    hrEmployeeInstance.DepartmentID = new Guid(deptId);//部门
                    hrEmployeeInstance.PostID = new Guid(positionId);//岗位
                    hrEmployeeInstance.BirthDate = hrCandidateEntry.BirthDay;//出生日期
                    hrEmployeeInstance.TopDegree = hrCandidateEntry.Degree;//学历
                    hrEmployeeInstance.EmployeeStatus = 2;//试用期
                    hrEmployeeInstance.JoinDate = DateTime.Now;//入职日期
                    hrEmployeeInstance.EmployeeType = new Guid("8D7C895F-1DAD-4C72-A299-1EC9C9D13BC3");//试用员工
                    hrEmployeeInstance.AddTime = DateTime.Now;
                    hrEmployeeInstance.AddUser = this.User.UserID;
                    //根据部门ID获取部门DeptPath
                    string deptCondition = string.Format("DeptID='{0}'", deptId);
                    BaseEntity deptinstance = ZX.Common.Globals.getEntity("DatDepartment") as BaseEntity;
                    ZX.BLL.Extend.BaseBussnies DeptBll = new ZX.BLL.Extend.BaseBussnies(deptinstance);
                    ZX.EHR.Library.DatDepartment deptInfo = DeptBll.GetEntityByCondition(deptCondition) as ZX.EHR.Library.DatDepartment;//获取该部门信息
                    string sequenceNum = deptInfo.DeptPath; //获取DeptPath
                    //获取员工工号
                    string num = this.GetSeqNum(sequenceNum);
                    if (num == "-1" && num.Substring(0, 2) == "e_")
                    {
                        HttpContext.Current.Response.Write("-1");
                        return;
                    }
                    hrEmployeeInstance.EmployeeCode = num;//员工工号
                    ZX.BLL.Extend.BaseBussnies hrEmployeeBll = new ZX.BLL.Extend.BaseBussnies(hrEmployeeInstance);
                    hrEmployeeBll.Insert();
                    HttpContext.Current.Response.Write("0");
                }
                catch(Exception ex)
                {
                    HttpContext.Current.Response.Write("e_"+ex.Message);
                }
            }
            if (flag.Trim() == "renshishiwu") //人事事务处理，包括在职转不在职，不在职转在职，辞职，辞退，离退休，
            {
                string id = this.GetStringFromQueryString("id", string.Empty);//员工ID
                if (id == string.Empty)
                {
                    HttpContext.Current.Response.Write("-1");
                    return;
                }
                try
                {
                    ZX.EHR.Library.hrEmployee instance = ZX.Common.Globals.getEntity("hrEmployee") as ZX.EHR.Library.hrEmployee;
                    ZX.BLL.Extend.BaseBussnies hrBll = new ZX.BLL.Extend.BaseBussnies(instance);
                    string condition = string.Format("ID='{0}'", id);
                    ZX.EHR.Library.hrEmployee o = hrBll.GetEntityByCondition(condition) as ZX.EHR.Library.hrEmployee;
                    o.EmployeeStatus = 2;
                    bool rs = hrBll.Update(o);
                    if (rs)
                        HttpContext.Current.Response.Write("0");
                    else
                        HttpContext.Current.Response.Write("-1");
                    return;
                }
                catch { }
                HttpContext.Current.Response.Write("-1");
            }
        }

        /// <summary>
        /// 根据部门deptPath获取部门员工工号
        /// </summary>
        /// <param name="deptPath"></param>
        /// <returns></returns>
        private string GetSeqNum(string deptPath)
        {
            try
            {
                string condition = string.Format("SequenceName='{0}'", deptPath);
                BaseEntity instance = ZX.Common.Globals.getEntity("Sequence") as BaseEntity;
                ZX.BLL.Extend.BaseBussnies SequenceBll = new ZX.BLL.Extend.BaseBussnies(instance);
                IList<BaseEntity> list = SequenceBll.GetEntitysByCondition(condition);
                if (list == null || list.Count == 0)//该部门未分配或由上级部门分配 
                {
                    int index = deptPath.LastIndexOf("-");
                    if (index < 1) //该部门没有上级部门
                    {
                        return "-1";
                    }
                    else //有上级部门，寻找上级部门工号段
                    {
                        string parentDeptPath = deptPath.Substring(0, index);
                        return GetSeqNum(parentDeptPath);
                    }
                }
                else //该部门已分配工号段
                {
                    //工号长度
                    ZX.DBModule.Sequence tempSysSequence = list[0] as ZX.DBModule.Sequence;
                    int numeLen = tempSysSequence.NumLength;
                    //生成工号
                    Int64 num = ZX.BLL.IDMaker.GetSequenceNum(deptPath);
                    string sequenceNum = num.ToString();
                    if (numeLen > num.ToString().Length)
                    {
                        for (int i = 0; i < numeLen - num.ToString().Length; i++)
                        {
                            sequenceNum = "0" + sequenceNum;
                        }
                    }
                    return sequenceNum; //正确分配工号
                }
            }
            catch (Exception ex)
            {
                return "e_" + ex.Message;
            }
        }
    }
}